//
// Created by xusun on 2022/1/28.
//
#include<vector>

using namespace std;

class Solution {
public:
    int singleNumberOpt(vector<int> &nums) {
        int a = 0;
        for (int i: nums) a ^= i;
        return a;
    }

    int singleNumber(vector<int> &nums) {
        int min_val = INT_MAX;
        int max_val = INT_MIN;
        for (int num: nums) {
            if (num < min_val) min_val = num;
            if (num > max_val) max_val = num;
        }
        for (int i = min_val; i <= max_val; i++) {
            int count = 0;
            for (int j: nums) {
                if (j == i) {
                    count++;
                    if (count % 2 == 0)break;
                }
            }
            if (count % 2 == 1)return i;
        }
        return 0;
    }
};
